package example.movieRental.beforeRF;

import java.util.Enumeration;
import java.util.Vector;

/**
 * Created by thinkpad on 2015/2/8.
 */
//Customer.java
//Customer类表示顾客，它还提供一个制造报表的方法
public class Customer {
    private String name;
    private Vector<Rental> rentals = new Vector<Rental>();

    public Customer(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void addRental(Rental r) {
        rentals.addElement(r);
    }

    public String statement() {
        double totalAmout = 0; //消费金额
        int frequentRenterPoints = 0;//常客积分
        Enumeration<Rental> rs = rentals.elements();
        String result = "Rental Record for" + this.getName() +"\n";
        while(rs.hasMoreElements()) {
            double thisAmout = 0;
            Rental each = (Rental)rs.nextElement();

            switch(each.getMovie().getPriceCode()){//各种影片的价格不同
                case Movie.REGULAR:
                    thisAmout += 2;
                    if(each.getDaysRented()>2)
                        thisAmout += (each.getDaysRented()-2)*1.5;
                    break;
                case Movie.NEW_RELEASE:
                    thisAmout += each.getDaysRented()*3;
                    break;
                case Movie.CHILDRENS:
                    thisAmout += 1.5;
                    if(each.getDaysRented()>3)
                        thisAmout += (each.getDaysRented()-3)*1.5;
                    break;
            }
            //累计积分
            frequentRenterPoints ++;
            if((each.getMovie().getPriceCode()==Movie.NEW_RELEASE)&&
                    each.getDaysRented()>1) frequentRenterPoints ++;
            //显示此次租赁的数据
            result += "\t" +each.getMovie().getTitle() + "\t" + String.valueOf(thisAmout) + "\n";
            totalAmout += thisAmout;
        }
        result += "Amout owed is" + String.valueOf(totalAmout) + "\n";
        result += "You earned" + String.valueOf(frequentRenterPoints) + "frequent renter points";
        return result;
    }
}
